<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<!-- <div class="layui-card-header table-operate-btn">
							<span class="marign_right10">全部代理商</span>
							<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='getCheckData'>商户划拨</button>
							<button class="layui-btn layui-btn-danger layui-btn-sm" id="del">删除</button>
						</div> -->
						<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="会员编号" name="customerid" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">手机号/姓名：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="手机号/姓名" name="keyword" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">月维度：</label>
									<div class="layui-input-inline">
										<input class="layui-input yue" id="test1" placeholder="月维度" name="dates" autocomplete="off">
										<!-- <input class="layui-input layui-hide ri" id="test2" placeholder="时间" name="dates2" autocomplete="off"> -->
									</div>
								</div>
								<!-- <div class="layui-inline search_inline">
									<label class="layui-form-label">顶级伙伴：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="顶级伙伴" name="root_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">上级伙伴：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="上级伙伴" name="parent_id" autocomplete="off">
									</div>
								</div> -->
								
								<div class="layui-inline search_inline">
									<label class="layui-form-label">顶级伙伴：</label>
									<div class="layui-input-inline">
										<input class="layui-input input_icon" readonly="readonly" placeholder="顶级伙伴" name="root_name" autocomplete="off">
										<input class="layui-hide" name="rootid" />
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">上级伙伴：</label>
									<div class="layui-input-inline">
										<input class="layui-input input_icon" readonly="readonly" placeholder="上级伙伴" name="parent_name" autocomplete="off">
										<input class="layui-hide" name="parentid" />
									</div>
								</div>
								
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->

							<!-- <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table> -->

							<table class="layui-table" lay-data="{id: 'test-table-operate',height: 'full-105'}">
								<thead>
									<tr>
										<!-- <th lay-data="{fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo'}" rowspan="2">操作</th> -->
										<th lay-data="{field:'name', width:100}" rowspan="2">姓名</th>
										<th lay-data="{field:'memberid', width:120}" rowspan="2">会员ID</th>
										<th lay-data="{}" colspan="4">拓展奖</th>
										<th lay-data="{}" colspan="4">推广奖</th>
										<th lay-data="{field:'a', width:120,templet: '#fanxian'}" rowspan="2">激活返现</th>
										<th lay-data="{field:'b', width:120,templet: '#huiyuan'}" rowspan="2">会员返佣</th>
										<th lay-data="{field:'c', width:120,templet: '#tuanjian'}" rowspan="2">团建返佣</th>
										<th lay-data="{field:'parent_id', width:180,templet: '#parent_id'}" rowspan="2">上级伙伴</th>
										<th lay-data="{field:'root_id', width:180,templet: '#root_id'}" rowspan="2">顶级伙伴</th>
									</tr>
									<tr>
										<th lay-data="{field:'d',width:200,templet: '#tuozhan'}">拓展奖</th>
										<th lay-data="{field:'d', width:200,templet: '#tmpos'}">MPOS</th>
										<th lay-data="{field:'d', width:200,templet: '#tmposvip'}">MPOS会员</th>
										<th lay-data="{field:'d', width:200,templet: '#tznpos'}">智能POS</th>
										
										<th lay-data="{field:'e',width:200,templet: '#tuiguang'}">推广奖</th>
										<th lay-data="{field:'e',width:200,templet: '#gmpos'}">MPOS</th>
										<th lay-data="{field:'e',width:200,templet: '#gmposvip'}">MPOS会员</th>
										<th lay-data="{field:'e',width:200,templet: '#gznpos'}">智能POS</th>
									</tr>
								</thead>
							</table>

							<script type="text/html" id="tuozhan">
								({{d.d[0].turnover_direct ? number_format(d.d[0].turnover_direct) : '0.00'}})
								{{d.d[0].profit_direct ? number_format(d.d[0].profit_direct) : '0.00'}}
							</script>
							<script type="text/html" id="tmpos">
								({{d.d[0].turnover_direct_vip0 ? number_format(d.d[0].turnover_direct_vip0) : '0.00'}})
								{{d.d[0].profit_direct_vip0 ? number_format(d.d[0].profit_direct_vip0) : '0.00'}}
							</script>
							<script type="text/html" id="tmposvip">
								({{d.d[0].turnover_direct_vip1 ? number_format(d.d[0].turnover_direct_vip1) : '0.00'}})
								{{d.d[0].profit_direct_vip1 ? number_format(d.d[0].profit_direct_vip1) : '0.00'}}
							</script>
							<script type="text/html" id="tznpos">
								{{ '0.00' }}
							</script>
							
							<script type="text/html" id="tuiguang">
								({{d.e[0].turnover_indirect ? number_format(d.e[0].turnover_indirect) : '0.00'}})
								{{d.e[0].profit_indirect ? number_format(d.e[0].profit_indirect) : '0.00'}}
							</script>
							<script type="text/html" id="gmpos">
								({{d.e[0].turnover_indirect_vip0 ? number_format(d.e[0].turnover_indirect_vip0) : '0.00'}})
								{{d.e[0].profit_indirect_vip0 ? number_format(d.e[0].profit_indirect_vip0) : '0.00'}}
							</script>
							<script type="text/html" id="gmposvip">
								({{d.e[0].turnover_indirect_vip1 ? number_format(d.e[0].turnover_indirect_vip1) : '0.00'}})
								{{d.e[0].profit_indirect_vip1 ? number_format(d.e[0].profit_indirect_vip1) : '0.00'}}
							</script>
							<script type="text/html" id="gznpos">
								{{'0.00'}}
							</script>
							
							<script type="text/html" id="fanxian">
								{{d.a[0].profit_direct ? number_format(d.a[0].profit_direct) : '0.00'}}
							</script>
							<script type="text/html" id="huiyuan">
								{{d.b[0].profit_indirect ? number_format(d.b[0].profit_indirect) : '0.00'}}
							</script>
							<script type="text/html" id="tuanjian">
								{{d.c[0].profit_indirect ? number_format(d.c[0].profit_indirect) : '0.00'}}
							</script>
								
							<script type="text/html" id="parent_id">
								{{ d.parent ? d.parent[0].mobile+ ',' + (d.parent[0].name ? d.parent[0].name : '') : '' }}
							</script>
							<script type="text/html" id="root_id">
								{{ d.root ? d.root[0].mobile+ ',' + (d.root[0].name ? d.root[0].name : '') : '' }}
							</script>
							
							<script type="text/html" id="test-table-operate-barDemo">
								<!-- <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a> -->
								<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>
								<!-- <a class="layui-btn layui-btn-xs" lay-event="business_edit">商户划拨</a> -->
							</script>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form','laydate'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					admin = layui.admin;
				$('input[name=dates]').val(getmonth())
				var _data = {
					dates: getmonth().replace(/-/ig,'')
				}
				
				agent_type_show('option')
				merchant_status_show('option')
				initdata(_data);
				
				laydate.render({
					elem: '#test1',
					type: 'month',
				});
				
				function initdata(_data) {
					table.reload('test-table-operate', {
						page: true,
						method: 'get',
						url: server.queryprofit_member,
						toolbar: true,
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.customer.pager.total, //解析数据长度
								"data": res.customer.data //解析数据列表
							};
						},
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						where: _data,
						limit: limit,
						limits: limits,
					});
				}


				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					_data = data.field;
					_data.dates = data.field.dates.replace(/-/ig,'')
					initdata(_data);
					return false;
				});

				$("button[type=reset]").on("click", function() {
					_data.dates = getmonth().replace(/-/ig,'')
					// initdata(_data);
					location = location
					document.getElementById("form").reset();
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});

				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if (obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							obj.del();
							layer.close(index);
						});
					} else if (obj.event === 'edit') {
						layer.open({
							type: 2,
							title: '编辑',
							shadeClose: false,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['50%', '70%'],
							content: '../model/edit_add.html?id=' + data.id,
							end: function() {}
						});
					}
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							console.log(data);
							var id_arr = [];
							for (var i = 0; i < data.length; i++) {
								id_arr.push(data[i].id)
							}
							if (data.length > 0) {
								layer.open({
									type: 2,
									title: '商户划拨',
									shadeClose: false,
									shade: 0.5,
									maxmin: true, //开启最大化最小化按钮
									area: ['60%', '60%'],
									content: '../model/shop_transfer.html',
									end: function() {},
									success: function(layero, index) {
										var body = layer.getChildFrame('body', index);
										body.find("input[name=id]").val(id_arr.join(','));
									}
								});
							} else {
								layer.msg('至少选择一个')
							}
						},
					};

				$('.table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

				$('#del').on('click', function() {
					layer.confirm('真的删除数据吗？', function(index) {
						// obj.del();
						layer.close(index);
					});
				});
			});
		</script>
	</body>
</html>
